16 results
6 - Special Functions
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 259-284
-
- Chapter
- Export citation
-
Summary
Introduction
The main objective of this chapter is familiarization with a variety of numerical methods that are essential for solving advanced problems of applied physics and engineering. With the help of suitable examples, basic skills on appropriately using these methods for various applications in physics are provided.
The chapter focuses on the following special second order differential equations, which are known to have standard functional form and/or analytical solutions.
• Bessel's equation (Section 6.2)
• Legendre's equation (Section 6.3)
• Laguerre's equation (Section 6.4)
• Hermite's equation (Section 6.5)
The solutions of these equations are referred to as ‘special functions’, which are significantly different from standard functions like sine/cosine, exponential and logarithmic functions. This chapter also describes the use of quadrature methods of integration for calculating improper integrals, which are either infinite in the interval of integration, or the interval of integration has an infinite bound. The quadrature methods discussed in this chapter are as follows:
• Gauss–Legendre (Section 6.6.1)
• Gauss–Laguerre (Section 6.6.2)
• Gauss–Hermite (Section 6.6.3)
The chapter has been written in a manner so as to develop the necessary skills of the reader to evaluate certain integrals that are generally not discussed in introductory physics classes because they involve advanced calculations.
Bessel Function of the First Kind
Bessel functions have several applications in physics. They arise while solving Laplace's and Helmholtz equations in spherical and cylindrical coordinates. The functions are also useful while solving problems based on electromagnetic wave propagation and Schrödinger's equation.
The general features of the Bessel function are as follows.
1. Bessel functions (order n) of the first kind (Jn(x)) are the solutions (y(x)) of the differential equation given in Eqn. 6.1.
A second order differential equation can be written in the form
For solving Eqn. 6.1 with the finite difference method, it is necessary to first define the functions f(x), g(x), and r(x)in the following manner.
The function for the finite difference method has already been explained in detail in Chapter 4. This function can be written in an executable file, ‘differentiation.sci’ (for example) and can be loaded using the following Scilab command.
Figure 6.1 shows the zero order Bessel function of the first kind. It has been generated using the following Scilab program.
4 - Ordinary Differential Equation
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 135-228
-
- Chapter
- Export citation
-
Summary
Introduction
Differential equations are key mathematical tools for modelling physics problems. They are frequently used in all branches of physics while expressing the variation in one quantity w.r.t. the other. There are various kinds of differential equations, such as:
• Ordinary differential equations with initial and boundary value problems.
• Partial differential equations involving functions of multiple independent variables and their partial derivatives.
This chapter introduces the necessary numerical tools for determining approximate solutions of ordinary differential equations. It focuses only on initial and boundary value problems involving first and second order ordinary linear differential equations. These equations contain functions of one independent variable, and derivatives in that variable.
There are several numerical techniques for determining the solutions of differential equations. In this chapter, some commonly used methods have been explained. Section 4.2 shows the use of Euler's method to determine the solution of a differential equation. This is followed by modified Euler's method in Section 4.3, Runge–Kutta second order method in Section 4.4 and Runge–Kutta fourth order method in Section 4.5. A graphical comparison of these four methods is presented in Section 4.6. In Section 4.7, a quick review of the finite difference method has been provided for second order boundary value problems. Some advanced application problems of physics involving the first and second order differential equations have been discussed in Section 4.8.
This chapter uses the plotting skills developed in the second chapter. The reader is encouraged to refine their understanding of the plotting techniques.
Euler's Method
This is the most basic method of numerical integration. It is a first order method for approximating solutions of differential equations. This method uses the initial value as the starting point and approximates the next point of the solution curve using a tangent line to that point. The accuracy crucially depends on the step size used to approximate the subsequent point on the solution curve.
The algorithm for writing a Scilab program based on Euler's method is explained in Section 4.2.1 (first order) and in Section 4.2.2 (second order) with the help of suitable examples.
List of Figures
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp xi-xvi
-
- Chapter
- Export citation
Frontmatter
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp i-iv
-
- Chapter
- Export citation
Appendix
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 349-370
-
- Chapter
- Export citation
-
Summary
Appendix
2 - Plotting and Graphics Design
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 37-94
-
- Chapter
- Export citation
-
Summary
Introduction
The science of physics generally deals with physical phenomena where one quantity (called an independent variable) is related to another quantity (called a dependent variable) through a mathematical equation. The graphical representation of these data is a convenient tool for deciphering this scientific information. It is of utmost importance that the experimental data should be plotted very carefully so that it is easy to appropriately visualize and interpret the relationship between the dependent and independent variables. For example, it is always advisable to
• Choose the units of the coordinate axes in an appropriate manner.
• Choose the coordinate axes so that the entire data are accommodated.
• Choose logarithmic scales if the range of variables is large.
• Interpolate the data to generate a smooth curve traversing through the data points.
• Mark the data points with markers and error bars wherever available.
• Label the graph properly and write a concise title that summarizes the graph.
• Describe each part of the graph with the help of suitably placed legends.
This chapter introduces the reader to various plotting commands invariably used in this book for developing meaningful graphs. The importance of this chapter lies in the fact that it gives an overview on writing small user-defined functions for generating self-explanatory graphs, instead of writing long codes.
The graphical representation of data can be formatted by three methods in Scilab
• By using the figure and axes properties present in the main menu bar of the graphical window.
• By using Scilab instructions at the command line on the console.
• By writing user-defined functions and invoking them at the console.
The first method is trivial and is left for the reader to explore. In most of the following chapters, graphs and plots have been formatted using small functions that are executed in a script. The major focus of this chapter is to introduce the reader to this kind of formatting tool. However, for completeness, direct command line instructions have also been mentioned wherever possible.
The layout of this chapter is as follows. The Scilab commands ‘plot’ and ‘plot2d,’ have been used in this book for generating graphs. Section 2.2 starts with highlighting the basic difference between these two commands and manipulating them so that they are on equal footing. This section also focuses on writing small functions for editing the coordinate axes.
5 - Integration and Differentiation
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 229-258
-
- Chapter
- Export citation
-
Summary
Introduction
The fundamental theorem of calculus closely relates integration to differentiation; it implies that integration can be considered as an inverse operation of differentiation, in the sense that, when a continuous function is integrated and then differentiated, it gives back the original function.
Integration refers to the area under the curve defined by a function f in a given interval [a, b]. If x is variable of integration, then the definite integral (y) is given by Eqn. 5.1.
There are innumerable examples in physics that require integral calculus. For instance, simulations of classical mechanics problems may require evaluation of velocity from the acceleration of a body; and displacement of an object from its velocity profile. However, sometimes direct calculations become formidable or intractable, and direct integration rules have to be replaced by approximate numerical methods.
Differentiation refers to finding the rate of change of a dependent quantity (y) with respect to a change in independent quantity (x), i.e. dy/dx . There are countless applications of differential calculus in physics, such as determination of slope and tangent of geometric curves, especially when the rate of change is not constant.
This chapter starts with a discussion on various numerical techniques used for estimating the definite integral of a function. Improper integrals will be discussed in Chapter 6 (on Special Functions). This is followed by a quick overview of the methods of differential calculus which are often used in Scilab.
The layout of this chapter is as follows. In Section 5.2, the built-in Scilab functions dedicated to computation of definite integrals are discussed. User-defined customized Scilab functions based on trapezoidal and Simpson's methods are discussed in Sections 5.3 to 5.5. The method of differentiation is discussed in Section 5.6. The knowledge acquired in all these sections is applied to various advanced physics problems in Section 5.7.
Built-in Scilab Functions for Integration
Scilab has several built-in functions to calculate definite integrals. In this book, two built-in functions have been used for integration, namely,
• intg
• integrate
intg
Consider the definite integral given in Eqn. 5.2.
In order to use the built-in Scilab function, the first step is to define the function that has to be integrated. This is shown in the following.
7 - Fourier Analysis
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 285-314
-
- Chapter
- Export citation
-
Summary
Introduction
The theory of Fourier series and Fourier integrals is of great importance for a wide range of scientific applications, such as in acoustics, optics and signal processing. The Fourier series is a mathematical representation of a continuous periodic function as an infinite sum of sinusoidal waves. The Fourier analysis is an excellent method to decompose an arbitrary function into sinusoidal components and solve it to get analytical solutions that are otherwise difficult to obtain.
Fourier transform is the frequency domain representation of continuous time signals. It results when the period of a time signal is stretched and allowed to approach infinity.
This chapter introduces the reader to write Scilab programs for computation of Fourier series of various periodic functions. An outline of the chapter is as follows. Section 7.2 discusses the generation of periodic functions. A quick recapitulation of the Fourier series and the significance of harmonics are done in Sections 7.3 and 7.4, respectively. The method of writing Scilab programs for determining Fourier series of various periodic functions has been explained in Section 7.5. In Section 7.6, Fourier transform of some commonly used functions has been discussed. Section 7.7 winds up the chapter with a brief summary of the Fourier analysis. Some practice questions have been given in Section 7.8.
Periodic Functions
A periodic function is a function whose value repeats itself after a regular interval which is called as ‘period’ of that function. As shown in Eqn. 7.1, if function f(x) is periodic and periodicity is d (a non-zero constant number), then for all the values of ‘x’,
Trigonometric functions are common examples of periodic functions. For example, consider the function in Eqns. 7.2. It has a base period equal to π/2.
The following Scilab function generates periodic functions over a given interval. If periodicity of the function is 2T, then, there can be two cases for generating a periodic function.
Case (I) The function is defined within the range [–T, T].
Case (II) The function is defined within the range [0, 2T].
The usefulness of these functions is explained with the help of the following examples.
Example 1: Suppose f(x) is a periodic function in the interval [–2, 2] such that,
The function in Eqn. 7.3 has a periodicity of 4. The following Scilab code generates this periodic function in the interval [–8, 8]. The graph is shown in Figure 7.1.
References
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 371-372
-
- Chapter
- Export citation
Contents
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp v-x
-
- Chapter
- Export citation
3 - Least Square Curve Fitting
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 95-134
-
- Chapter
- Export citation
-
Summary
Introduction
Curve fitting refers to the process of generating a curve that fits to a set of data points. For example, consider a series of data points that consists of ‘n’ data points [(x1,y1),(x2,y2 )… (xn,yn)]. The variables yi are related to their respective xi through a function f(xi). In this configuration, the residual (Ri) of the ith data pair is defined as the difference between the theoretical value and the observed value (Eqn. 3.1).
The aim of curve fitting is to minimize Ri, i.e., to minimize the difference between expected values and the observed values. From Eqn. 3.1, it is evident that the value of Ri can be positive for some values of ‘i’ and it can be negative for others. Therefore, the objective of ‘least square’ in curve fitting is to minimize the sum of square of all the residuals.
In the following sections, the least square fitting of different types of data sets will be discussed. The curve fitting for a linear and a non-linear data set is described in Sections 3.2 and 3.3 respectively. This is followed by polynomial fitting in Section 3.4. The next section explains the fitting procedure using built-in Scilab function. Applications of these methods have been discussed in Section 3.6.
Fitting of Linear Data
Consider a data set having ‘n’ data points [(x1,y1),(x2,y2),… (xn,yn)]. The linear relation between xi and yi is given by Eqn. 3.2.
Eqn. 3.2 represents a straight line whose slope is ‘m’ and the intercept on y-axis is ‘c’. The residual (Ri) is given by Eqn. 3.3.
Eqn. 3.4 gives the sum of squares of all the residuals.
The objective of least square fitting method is to find the values of m and c, such that they minimize S. The minimum value of S can be determined by differentiating it w.r.t. the slope and the constant and then equating the differential to zero, i.e.
In Eqn, 3.5,
Simultaneous solution of Eqns. 3.7 and 3.9 will give,
Eqns. 3.7 and 3.9 can also be written in the matrix notation, i.e.
Eqn. 3.12 implies that
In Eqn. 3.14, the first element of the matrix C will give the slope of the best fit curve. The second element of this matrix will give the intercept on the y-axis.
Index
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 373-375
-
- Chapter
- Export citation
1 - Matrices and Vector Spaces
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 1-36
-
- Chapter
- Export citation
-
Summary
Introduction
Matrices are often aptly described as key to solve everything in the scientific world. This chapter expounds the usefulness of vectors and matrices that occur in many kinds of problems across the disciplines. They are used to study innumerable physical phenomena such as, motion of rigid bodies, eigen states of a quantum mechanical system, electrical networks and coordinate system conversion.
In Scilab, matrix computation forms the basis of all calculations. This chapter recapitulates the basic Scilab rules that have to be followed for creating and editing matrices. It also summarizes the arithmetic operations that can be performed on matrices. Section 1.2 gives an overview on different ways of generating a matrix and its elements. Some special types of matrices such as row/column vector, diagonal matrix, identity matrix and triangular matrices have been introduced in Section 1.3. Matrix operations such as row/column operation, conjugation, scalar/vector multiplication and division have been explained in Section 1.4. The laws of vector algebra have been outlined in Section 1.5. Some interesting examples of applications and use of matrices in physical sciences have been discussed in Section 1.6.
Creation of a Matrix
Matrices are rectangular arrangements of ‘m’ rows and ‘n’ columns; an arrangement of m rows and n columns is called an (m × n) matrix. If it contains only one row or only one column, then it is called a vector. There are several ways of defining vectors and matrices in Scilab. Some of them have been explained as follows.
1. The elements of a matrix are defined by writing them inside a square bracket, such that the elements of a row are separated by a comma or a white space. The elements of consecutive rows are separated by a semi-colon.
2. The elements of a matrix can be of several types and have been listed in Table 1.1. As can be seen in this table,
a. The elements can be real numbers.
b. The elements can be complex numbers. The complex number consists of a real part and/or an imaginary part.
c. The elements can be rational numbers, which are defined using the ‘rlist’ command of Scilab.
List of Tables
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp xvii-xviii
-
- Chapter
- Export citation
8 - Algebraic and Transcendental Equations
- Chetana Jain, University of Delhi
-
- Book:
- Computing in Scilab
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023, pp 315-348
-
- Chapter
- Export citation
-
Summary
Introduction
In mathematics, an algebraic expression is a combination of integers, variables, and algebraic operations such as summation, subtraction, product, division, and exponentiation. Equating two such algebraic expressions gives rise to an algebraic equation. For example, Eqns. 8.1–8.2 are algebraic expressions, whereas Eqns. 8.3–8.4 are algebraic equations.
There are different kinds of algebraic equations, such as, linear equations, non-linear equations (quadratic, cubic, and higher order polynomial equations) and exponential equations. The aim of this chapter is to find solutions for these equations by making use of various numerical techniques and to determine a set of values of the unknown variables contained in these equations. In this chapter, the Gauss–Seidel and the Gaussian elimination methods have been used for solving systems of linear equations, which involve ‘n’ equations and an equal number of unknown variables.
Transcendental equations are encountered ubiquitously in theoretical physics. They consist of transcendental functions that cannot be expressed in the form of finite sequences of algebraic operations. Elementary transcendental functions are logarithmic, trigonometric, exponential, and hyperbolic functions. These equations commonly occur while solving heat transfer problems and studying diffraction patterns. This chapter focuses on Scilab programs for determining the approximate numerical solution of non-linear and transcendental equations using the following iterative numerical techniques,
• Bracketing methods
• Bisection method
• Method of false position
• Open methods
• Secant method
• Newton–Raphson method
This chapter is arranged such that Section 8.2 recapitulates the built-in functions of Scilab that are often used for solving linear, quadratic, and polynomial equations. The reader is advised to revise the chapter on matrices before attempting to go through this section. In Section 8.3, the Gauss–Seidel method has been discussed along with its pitfalls. In Section 8.4, a brief overview of the Gaussian elimination method for solving system of linear equations has been provided. It is followed by an explicit explanation of the Scilab program based on this numerical technique. Section 8.5 discusses a variant of the Gaussian elimination method. This version re-orients the pivot elements of the Gaussian elimination method. The technique of bisection method has been explained in Section 8.6. The other techniques for solving non-linear and transcendental equations, such as the Regula Falsi method, the Secant method, and the Newton–Raphson method have been explained in Sections 8.7–8.9 respectively.
Computing in Scilab
- Chetana Jain
-
- Published online:
- 15 October 2023
- Print publication:
- 05 January 2023
-
- Textbook
- Export citation
-
SciLab is a free open-source computing and graphics tool that allows students to learn physical and mathematical concepts with ease. Computing in SciLab has been designed for undergraduate students of physics and electronics following the CBCS-LOCF syllabus, and with extensive coverage of concepts, it focuses primarily on the applications of SciLab in improving the problem-solving skills of readers. All these tools are classroom-tested and focus on data visualization and numerical computing with SCILAB. The book covers important topics like linear algebra, matrices, plotting tools, curve fitting, differential equations, integral calculus, Fourier analysis, and equation solving.